import type { Router } from 'vue-router';
import type { NavigationGuardNext, RouteLocationNormalized } from 'vue-router';
import NProgress from 'nprogress';
import 'nprogress/css/nprogress.css';

NProgress.configure({ showSpinner: false, easing: 'ease' });

export function setupTagViewGuard(router: Router) {
  router.beforeEach(
    async (
      to: RouteLocationNormalized,
      from: RouteLocationNormalized,
      next: NavigationGuardNext
    ) => {
      NProgress.start();

      next();
    }
  );

  router.afterEach(() => {
    NProgress.done();
  });
}
